package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author DBX
 * @effect foreach循环
 * @date 2021/09/03/10:47
 */
public class NewForDemo {
    public static void main(String[] args) {
        int[] i = new int[]{1,2,3,4,4,5,6,7,7,5,4,3,3,4,5,3,3};
        for (int i1 : i) {
            System.out.print(i1+" ");
        }
        Collection<String> c = new ArrayList<>();
        c.add("h");
        c.add("e");
        c.add("l");
        c.add("l");
        c.add("o");
//        新循环是编译器认可而非虚拟机，编译器在编译代码时会将新循环遍历数组改回成普通for循环遍历，
//          所以在遍历集合时，不能在里面用集合增删
        for (String s : c) {
//            c.remove("h");
            System.out.print(s);
        }
        Iterator<String> t = c.iterator();
        while (t.hasNext()){
            String s = t.next();
            System.out.print(s);
        }
    }
}
